<?php

class Jf_Module_Plugin_Autoloader extends Jf_Controller_Plugin_Abstract {

    public function routeStartup (Jf_Controller_Request_Abstract $request, Jf_Controller_Response_Abstract $response) {
        self::run ();
    }

    public static function run () {
        $dispatcher = Jf_Controller_Dispatcher::getInstance ();
        $modules = unserialize (Jf_Global::get ('modules'));
        foreach ($modules as $module) {
            $module = ucfirst ($module);
            $loader = new Zend_Loader_Autoloader_Resource (array('basePath' => $dispatcher -> getModulePath ($module), 'namespace' => $module));
            $loader -> addResourceTypes (array('controller' => array('namespace' => 'Controller', 'path' => 'controllers'), 'model' => array('namespace' => 'Model', 'path' => 'models'), 'plugin' => array('namespace' => 'Plugin', 'path' => 'plugins'), 'block' => array('namespace' => 'Block', 'path' => 'blocks'), 'helper' => array('namespace' => 'Helper', 'path' => 'helpers'), 'validate' => array('namespace' => 'Validate', 'path' => 'validates'), 'service' => array('namespace' => 'Service', 'path' => 'services')));
            Zend_Loader_Autoloader::getInstance () -> unshiftAutoloader ($loader, $module);
        }
    }

}
